package com.chentf.es.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

/**
 * @author chentengfei
 * @desc 配置es客户端
 * @date 2022-03-30 15:57:45
 */
@Configuration
public class ElasticSearchRestClientConfig extends AbstractElasticsearchConfiguration {
    //这个client用来替换java中操作es的tranportClient(9300)对象
    @Override
    public RestHighLevelClient elasticsearchClient() {
        //定义客户端配置对象RestClient 9200
        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                //书写集群中所有节点
                .connectedTo("192.168.224.100:9200")
                .build();
        return RestClients.create(clientConfiguration).rest();
    }
}
